package b2.widget.fort
{
	import b2.config.*;
	import b2.net.*;
	import b2.util.*;
	
	import com.bit101.components.Text;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.Mouse;

	public class CampItem extends Sprite
	{
		public var campIndex:int;
		private var _selected:Boolean;
		private var tabItemBackground:Sprite;
		private var tabItemBackground2:Sprite;
		
		public function CampItem(campIndex:int)
		{
			super();
			this.campIndex = campIndex;
			var campConfig:CampConfig = Config.campConfigs[campIndex];
			//背景框
			var TabItemBackground:Class = ResourceHelper.getInstance().getClassByName("CampItemBgr");
			tabItemBackground = new TabItemBackground();
			addChild(tabItemBackground);
			//背景框
			var TabItemBackground2:Class = ResourceHelper.getInstance().getClassByName("CampItemBgr2");
			tabItemBackground2 = new TabItemBackground2();
			addChild(tabItemBackground2);
			//战役名字
			var nameText:TextField = new TextField();
			nameText.selectable = false;
        	nameText.autoSize = TextFieldAutoSize.LEFT;
			nameText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0xFFFF00);
			nameText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			nameText.text = campConfig.name;
			nameText.x = 10;
			nameText.y = 3;
			addChild(nameText);
			//关数
			var battleNumText:TextField = new TextField();
			battleNumText.selectable = false;
        	battleNumText.autoSize = TextFieldAutoSize.LEFT;
			battleNumText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFFFF);
			battleNumText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			//难度
			var difficultyText:TextField = new TextField();
			difficultyText.selectable = false;
        	difficultyText.autoSize = TextFieldAutoSize.LEFT;
			difficultyText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFFFF);
			difficultyText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 50, BitmapFilterQuality.HIGH)];
			//比赛战役
			if (campConfig.type == 2)
			{
				difficultyText.text = "官方比赛"; 
				battleNumText.text = "";
			}
			//比赛战役
			else if (campConfig.type == 1)
			{
				difficultyText.text = "对战地图"; 
				battleNumText.text = campConfig.recommendedPlayer + "v" + campConfig.recommendedPlayer;
			}
			//普通战役
			else
			{
				difficultyText.text = campConfig.getDiffStar();
				battleNumText.text = campConfig.battleIndex.length + "关";
			}
			battleNumText.x = 165 - battleNumText.width;
			battleNumText.y = 6;
			addChild(battleNumText);
			difficultyText.x = 10;
			difficultyText.y = 23;
			addChild(difficultyText);
			selected = false;
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		public function set selected(value:Boolean):void
		{
			_selected = value;
			tabItemBackground.visible = !value;
			tabItemBackground2.visible = value;
			this.filters = null;
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			if (!selected)
			{
				Mouse.cursor = "button";
				this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
			}
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
		}
	}
}